home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / StringInfo.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  2.9 KB  |  119 lines  |  [TEXT/R*ch]

  1. /*
  2.     File:        StringInfo.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef    __DEBUGASSERT__
  15. #include "DebugAssert.h"
  16. #endif
  17.  
  18. #ifndef __DEBUGGINGGEAR__
  19. #include "DebuggingGear.h"
  20. #endif
  21.  
  22. #ifndef __STRINGINFO__
  23. #include "StringInfo.h"
  24. #endif
  25.  
  26. /***********************************|****************************************/
  27.  
  28. TStringInfo::TStringInfo ( const char * str )
  29. {
  30.     SetString ( (const void *) str, strlen ( str ) );
  31. }
  32.  
  33. /***********************************|****************************************/
  34.  
  35. TStringInfo::TStringInfo ( const Str255 str )
  36. {
  37.     SetString ( (const void *) &str[1], str [ 0 ] );
  38. }
  39.  
  40. /***********************************|****************************************/
  41.  
  42. TStringInfo::TStringInfo ( const RString& rStr )
  43. {
  44.     SetString ( (const void *) rStr.body, rStr.dataLength );
  45. }
  46.  
  47. /***********************************|****************************************/
  48.  
  49. TStringInfo::TStringInfo ( const void * data, unsigned long length )
  50. {
  51.     SetString ( data, length );
  52. }
  53.  
  54. /***********************************|****************************************/
  55.  
  56. TStringInfo::~TStringInfo ()
  57. {
  58. }
  59.  
  60. /***********************************|****************************************/
  61.  
  62. short TStringInfo::Count ( char c ) const
  63. {
  64.     return fCount [ (unsigned short) c ];
  65. }
  66.  
  67. /***********************************|****************************************/
  68.  
  69. short TStringInfo::First ( char c ) const
  70. {
  71.     return fFirst [ (unsigned short) c ];
  72. }
  73.  
  74. /***********************************|****************************************/
  75.  
  76. short TStringInfo::Last ( char c ) const
  77. {
  78.     return fLast [ (unsigned short) c ];
  79. }
  80.  
  81. /***********************************|****************************************/
  82.  
  83. void TStringInfo::SetString ( const char * str )
  84. {
  85.     SetString ( (const void *) str, strlen ( str ) );
  86. }
  87.  
  88. /***********************************|****************************************/
  89.  
  90. void TStringInfo::SetString ( const Str255 str )
  91. {
  92.     SetString ( (const void *) &str[1], str [ 0 ] );
  93. }
  94.  
  95. /***********************************|****************************************/
  96.  
  97. void TStringInfo::SetString ( const RString& rStr )
  98. {
  99.     SetString ( (const void *) rStr.body, rStr.dataLength );
  100. }
  101.  
  102. /***********************************|****************************************/
  103.  
  104. void TStringInfo::SetString ( const void * data, unsigned long length )
  105. {
  106.     //    Set the first, count, and last arrays to 0
  107.     for (register unsigned short i = 0; i < 256; ++i)
  108.         fFirst[ i ] = fLast [ i ] = fCount [ i ] = 0;
  109.  
  110.     for ( i = 0; i < length; ++i ) {
  111.         fFirst [ (unsigned short) ( ((char *) data) [ length - i ] ) ] =  length - i;
  112.         char c = ((char *) data ) [ i ];
  113.         fCount [ (unsigned short ) c ] ++;
  114.         fLast [ ( unsigned short) c ] = i;
  115.     }
  116. }
  117.  
  118. /***********************************|****************************************/
  119.